package com.exp.bookhouse.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.exp.bookhouse.pojo.Order;
import com.exp.bookhouse.service.OrderService;
import com.exp.bookhouse.util.ApiJSONResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "订单管理接口",tags = "订单操作")
@RestController
@RequestMapping("/order")
public class OrderController {


    @Autowired
    private OrderService orderService;

    @ApiOperation(value = "订单保存", notes = "用户下单")
    @PostMapping
    public ApiJSONResult saveOrder(@ApiParam(value="订单信息", required = true) @RequestBody Order order) throws Exception {
        orderService.saveOrder(order);
        return ApiJSONResult.ok();
    }


    @ApiOperation(value = "订单查询", notes = "用户查询订单信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "页数", required = true, dataType = "Int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "显示记录数", required = true, dataType = "Int"),
            @ApiImplicitParam(paramType = "query", name = "payStatus", value = "订单状态", required = true, dataType = "Int"),
            @ApiImplicitParam(paramType = "query", name = "openid", value = "openid", required = true, dataType = "String")
    })
    @GetMapping("/openid")
    public ApiJSONResult getAllOrder(Integer pageNum, Integer pageSize, Integer payStatus, String openid){
        IPage<Order> allOrder = orderService.getAllOrder(pageNum, pageSize, payStatus, openid);
        return ApiJSONResult.ok(allOrder);
    }

}
